#include"BlockQueue.hpp"

void* Producer(void* arg)
{
  BlockQueue<int>* bq = (BlockQueue<int>*) arg;
  while(1)
  {
   // sleep(1);
    int data = rand()%100+1;
    bq->push(data);
   // cout<<"producer: "<<data<<endl;
   printf("producer: %d\n",data);
  }
}

void* Consumer(void* arg)
{
  BlockQueue<int>* bq = (BlockQueue<int>*)arg;
  while(1)
  {
    sleep(1);
    int data = 0;
    bq->pop(data);
   // cout<<"consumer: "<<data<<endl;
   printf("consumer: %d\n",data);
  }
}

int main()
{
srandom((unsigned int)time(nullptr));
pthread_t producer,consumer;

BlockQueue<int>* bq = new BlockQueue<int>;
pthread_create(&producer,nullptr,Producer,bq);
pthread_create(&consumer,nullptr,Consumer,bq);

pthread_join(producer,nullptr);
pthread_join(consumer,nullptr);
delete bq;
return 0;
}
